package com.dhh.util.calorie;

import java.util.HashMap;
import java.util.Map;

import com.dhh.util.CUtil;

public class BMRUtil {
	public static String AL_SEDENTARY = "Sedentary";
	public static String AL_LIGHT = "Light Activity";
	public static String AL_MODERATE = "Moderate Activity";
	public static String AL_VERY = "Very Active";
	public static String AL_EXTRA = "Extra Active";
	public static String G_MAN = "Male";
	
	private static Map<String,Double> acitivityLeveMap = new HashMap<String,Double>();
	static{
		acitivityLeveMap.put("Sedentary", Double.valueOf(1.2));
		acitivityLeveMap.put("Light Activity", Double.valueOf(1.375));
		acitivityLeveMap.put("Moderate Activity", Double.valueOf(1.55));
		acitivityLeveMap.put("Very Active", Double.valueOf(1.725));
		acitivityLeveMap.put("Extra Active", Double.valueOf(1.9));
	}
	
	
	public static double getBMR(double weight,int height,int age,boolean isMan){
		double bmr = 0;
		if(isMan){
			bmr = 66 + (13.7 * weight) + (5 * height) - (6.8 * age);
		}else{
			bmr = 655 + (9.6 * weight) + (1.8 * height) - (4.7 * age);
		}
		return (double)Math.round(bmr * 10) / 10;
	}
	
	public static int getCalorie(double weight,String height,int age,String gender,String activityLevel){
		weight = CUtil.convertToKG(weight);
		int h = CUtil.convertToCM(height);
		
		boolean isMan = G_MAN.equalsIgnoreCase(gender);
		double al = acitivityLeveMap.get(activityLevel);
		double bmr = getBMR(weight,h,age,isMan);
		double calorie = al*bmr;
		return (int) Math.round(calorie);
	}
	
	
}
